import { Module } from '@nestjs/common';
import { TypeOrmModule, TypeOrmModuleAsyncOptions } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { UsersModule } from './users/users.module';
import config from './utils/loader/config';
import { ChatModule } from './chat/chat.module';
import { RedisModule } from './common/redis.module';
import { BaiDuAiModule } from './bai-du-ai/bai-du-ai.module';
import { RsaModule } from './rsa/rsa.module';
@Module({
  imports: [
    
    ConfigModule.forRoot({
      isGlobal: true,
      load: [async () => await config()]
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (config: ConfigService) => {
        const dataSource = await import('../datasource.config');
        const options = dataSource.default.options;
        return {
          ...options,
          retryAttempts: 10,
          retryDelay: 3000,
          toRetry: (err) => {
            return true;
          },
        }
      },
      inject: [ConfigService]
    }),
    UsersModule,
    ChatModule,
    RedisModule,
    BaiDuAiModule,
    RsaModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule { }
